package org.spbsu.apco.server.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spbsu.apco.common.monitoring.event.ServiceEvent;
import org.spbsu.apco.common.monitoring.event.TaskEvent;
import org.spbsu.apco.common.task.core.WaitTask;
import org.spbsu.apco.server.monitoring.event.EventManager;
import org.spbsu.apco.server.monitoring.event.MonitorService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.Queue;

/**
 * User: mikpan
 * Date: 12/12/12
 * Time: 11:39 AM
 */
@Path("/events")
@Service
public class EventServiceImpl implements EventManager {
    private static final Logger LOG = LoggerFactory.getLogger(EventServiceImpl.class);

    @Resource
    private MonitorService monitorService;

    public EventServiceImpl() {
        LOG.info("EventService created");
    }

    @PUT
    @Path("/new")
    @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    @Override
    public void addEvent(ServiceEvent e) {
        monitorService.addEvent(e);
    }

    @GET
    @Path("/service/all")
    @Produces({MediaType.APPLICATION_XML})
    @Override
    public Queue<ServiceEvent> getEvents() {
        return monitorService.getEvents();
    }

    @GET
    @Path("/client/all")
    @Produces({MediaType.APPLICATION_XML})
    public Queue<TaskEvent> getClientEvents() {
        return monitorService.getTaskEvents();
    }
}
